home *** CD-ROM | disk | FTP | other *** search
- ;-----------------------------------------------------------------------------;
- ; LDE18.asm Ľſî┼ÆΦÄ«üiùΓôÇüj (C) ÄOû╪ÿaòF NIFTY SDR SDI00147 1989/7/15;
- ;-----------------------------------------------------------------------------;
- ; ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ èεû{ôIé╚âAâïâSâèâYâÇé═ë£æ║Äüé╠ébé≡ÄQÅ╞;
- ; ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ü@ ü@ü@ü@ü@ ì\æóë╗â}âNâìé═î├É∞Äüé╠éαé╠é≡Ägùp;
- ; ;
- ; ì∞ɼû@: ;
- ; optasm é≡ Use THREADs for Smaller OBJ(N) é╔é╡é─âAâZâôâuâïé╖éΘ ;
- ; ;
- ;-----------------------------------------------------------------------------;
- include lms3.inc ; ìéæ¼ì\æóë╗â}âNâì
- ; (c)S.Furukawa
- include minimac.inc ; movseg movdat movdatb
- ;-----------------------------------------------------------------------------;
- data segment word public ;
- extrn RBuff : byte ; ô╟ì₧é▌âoâbâtâ@
- extrn WBuff : byte ; Åæì₧é▌âoâbâtâ@
- extrn CrcTable : word ; éâéÆéâùpâeü[âuâï
- extrn CRC : word ; éâéÆéâ
- extrn DicSeg : word ; Ľſâoâbâtâ@
- ;
- WPoint dw ? ; Åæì₧é▌â|âCâôâ^
- InHandle dw ? ; ôⁿù═ânâôâhâï
- OutHandle dw ? ; Åoù═ânâôâhâï
- PushSp dw ? ; éôéÉæ▐ö≡ùpâÅü[âN
- SrcSize dw ?,? ; âtâ@âCâïâTâCâY
- DicSize dw ?,? ;
- CodeBuf db 33 dup(?) ; éWârâbâgùpâÅü[âN
- CmpLen dw ? ;
- DicPag dw ? ;
- DicLen dw ? ;
- SBufLen dw ? ;
- CPoint dw ? ;
- SftFlg db ? ;
- EndSrcFlg db ? ;
- MatchLen dw ? ;
- MatchSeg dw ? ;
- MatchAdr dw ? ;
- BCD dw ? ;
- BCD2 dw ? ;
- BCDSTR db 14 dup(?) ;
- ;
- MINWORD equ 3 ;
- MAXWORD equ 4003h ;
- data ends ;
- ;
- code segment byte public ;
- assume cs:code,ds:data,es:data ;
- ;
- public EnCode18 ;
- ;
- WBUFFEND equ 0fffh ;
- RBUFFEND equ 7fffh ;
- ;
- ;-------------------------------------------------------;
- ; ïñÆ╩âîâWâXâ^ò╧Éö ;
- ; ---------------- ;
- ; ds:[si] â\ü[âXâ|âCâôâ^ ;
- ;-------------------------------------------------------;
- BEGIN CodeFlush ;
- mov cx,CPoint ;
- mov bx,offset CodeBuf ;
- sub cx,bx ;
- mov di,WPoint ;
- .do ;
- mov al,[bx] ;
- inc bx ;
- .if <di a WBUFFEND> ;
- pushm ax,bx,cx ;
- mov dx,offset WBuff ;
- mov cx,di ;
- mov bx,OutHandle ;
- msdos 40h ;
- jc ErrOut ;
- cmp ax,cx ;
- jne ErrOut ;
- popm cx,bx,ax ;
- xor di,di ;
- .endif ;
- mov WBuff[di],al ;
- inc di ;
- .loop ;
- mov WPoint,di ;
- mov SftFlg,1 ;
- mov CodeBuf,0 ;
- mov CPoint,(offset CodeBuf)+1 ;
- ret ;
- ENDN CodeFlush ;
- ;-------------------------------------------------------;
- ; âfü[â^Åoù═ ;
- ; ---------- ;
- ; in cx ôKìçÆ╖ ;
- ; des -- ;
- ;-------------------------------------------------------;
- BEGIN OutPut ;
- push cx ;
- dec cx ;
- mov bx,CPoint ;
- .if <z> ;
- mov al,[si] ;
- mov [bx],al ;
- inc bx ;
- mov al,SftFlg ;
- or CodeBuf,al ;
- .else ;
- sub cx,3 ;
- mov dx,MatchSeg ;
- mov ax,MatchAdr ;
- sub dx,DicSeg ;
- test dh,00001000b ;
- .if <nz> ;
- or ax,8000h ;
- and dh,11110111b ;
- .endif ;
- mov [bx],ax ;
- inc bx ;
- inc bx ;
- shl dh,1 ;
- shl dh,1 ;
- or cx,dx ;
- xchg ch,cl ;
- mov [bx],cx ;
- inc bx ;
- inc bx ;
- .endif ;
- mov CPoint,bx ;
- shl SftFlg,1 ;
- .if <c> ;
- call CodeFlush ;
- .endif ;
- pop cx ;
- ret ;
- ENDN OutPut ;
- ;-------------------------------------------------------;
- ; ébéqébîvÄZ ;
- ; ---------- ;
- ; in cx,dx ;
- ; out -- ;
- ; des -- ;
- ;-------------------------------------------------------;
- BEGIN CrcCalc ;
- .if <cxnz> ;
- pushm si,dx,cx,bx,ax ;
- mov si,dx ;
- mov dx,CRC ;
- .do ;
- lodsb ;
- mov bl,dl ;
- xor bh,bh ;
- xor bl,al ;
- shl bx,1 ;
- mov ax,CrcTable[bx] ;
- mov bl,dh ;
- xor bh,bh ;
- xor bx,ax ;
- mov dx,bx ;
- .loop ;
- mov CRC,dx ;
- popm ax,bx,cx,dx,si ;
- .endif ;
- ret ;
- ENDN CrcCalc ;
- ;-------------------------------------------------------;
- ; âfü[â^ô╟é▌ì₧é▌ ;
- ; -------------- ;
- ; in cx ;
- ;-------------------------------------------------------;
- BEGIN ReSetBuf ;
- add si,cx ;
- sub SBufLen,cx ;
- mov ax,SBufLen ;
- .if <ax b CmpLen> ;
- .if <EndSrcFlg e FALSE> ;
- mov di,offset RBuff ;
- mov cx,(offset RBuff)+8003h ;
- sub cx,si ;
- movseg es,ds ;
- rep movsb ;
- mov dx,di ;
- mov cx,(offset RBuff)+8003h ;
- sub cx,di ;
- .if <SrcSize[2] e 0 and <cx a SrcSize>>
- mov cx,SrcSize ;
- mov EndSrcFlg,TRUE ;
- .endif ;
- add SBufLen,cx ;
- mov bx,InHandle ;
- msdos 3fh ;
- jc ErrOut ;
- cmp ax,cx ;
- jne ErrOut ;
- call CrcCalc ;
- sub SrcSize,ax ;
- sbb SrcSize[2],0 ;
- mov si,offset RBuff ;
- mov ax,SBufLen ;
- .if <ax b CmpLen> ;
- mov CmpLen,ax ;
- .endif ;
- .else ;
- mov CmpLen,ax ;
- .endif ;
- .endif ;
- ret ;
- ENDN ReSetBuf ;
- ;-------------------------------------------------------;
- ; îƒì⌡ SI --> CX
- ;-------------------------------------------------------;
- BEGIN Search ;
- mov es,DicSeg ;
- xor di,di ;
- mov dx,DicPag ;
- mov MatchLen,MINWORD ;
- .if <CmpLen be MINWORD> ;
- jmp #out ;
- .endif ;
- .if <dx ne 0> ;
- mov cx,8000h ;
- .else ;
- mov cx,DicLen ;
- .endif ;
- .do lp ;
- .do ;
- .if <dx e 0 and <cx be MINWORD>>
- jmp #out ;
- .endif ;
- .if <cx e 0> ;
- dec dx ;
- mov ax,es ;
- add ax,800h ;
- mov es,ax ;
- xor di,di ;
- .if <dx e 0> ;
- mov cx,DicLen
- .else ;
- mov cx,8000h
- .endif ;
- .endif ;
- or cx,cx ;
- mov al,[si] ;
- repnz scasb ;
- .enddo <nz> ;
- .if <cx be MatchLen> ;
- .break <dx e 0> ;
- mov ax,DicLen ;
- .break <dx e 1 and <ax b MatchLen>>
- .endif ;
- pushm cx,dx,si,di ;
- inc cx ;
- .if <cx a CmpLen> ;
- mov cx,CmpLen ;
- .else ;
- .if <dx e 1> ;
- add cx,DicLen ;
- .elseif <dx a 1> ;
- add cx,8000h ;
- .endif ;
- .if <cx a CmpLen> ;
- mov cx,CmpLen ;
- .endif ;
- .endif ;
- dec di ;
- mov dx,di ;
- mov bx,cx ;
- xor al,al ;
- repz cmpsb ;
- .if <z> ;
- popm di,si,ax,ax ;
- mov MatchLen,bx ;
- mov MatchAdr,dx ;
- mov MatchSeg,es ;
- .break ;
- .else ;
- sub bx,cx ;
- dec bx ;
- .if <bx a MatchLen> ;
- mov MatchLen,bx ;
- mov MatchAdr,dx ;
- mov MatchSeg,es ;
- .endif ;
- .endif ;
- popm di,si,dx,cx ;
- .enddo <> ;
- #out: mov cx,MatchLen ;
- .if <cx be MINWORD> ;
- mov cx,1 ;
- .endif ;
- ret ;
- ENDN Search ;
- ;-------------------------------------------------------;
- ; âJâEâôâgò\Ī CX
- ;-------------------------------------------------------;
- BEGIN Display ;
- push cx ;
- .if <cx e 1> ;
- mov ax,BCD ;
- inc al ;
- daa ;
- xchg ah,al ;
- adc al,0 ;
- daa ;
- xchg ah,al ;
- mov BCD,ax ;
- and ax,0f0fh ;
- or ax,3030h ;
- mov BCDSTR[3],ah ;
- mov BCDSTR[5],al ;
- mov ax,BCD ;
- mov cl,4 ;
- shr ax,cl ;
- and ax,0f0fh ;
- or ax,3030h ;
- mov BCDSTR[2],ah ;
- mov BCDSTR[4],al ;
- .else ;
- mov ax,BCD2 ;
- inc al ;
- daa ;
- xchg ah,al ;
- adc al,0 ;
- daa ;
- xchg ah,al ;
- mov BCD2,ax ;
- and ax,0f0fh ;
- or ax,3030h ;
- mov BCDSTR[10],ah ;
- mov BCDSTR[12],al ;
- mov ax,BCD2 ;
- mov cl,4 ;
- shr ax,cl ;
- and ax,0f0fh ;
- or ax,3030h ;
- mov BCDSTR[9],ah ;
- mov BCDSTR[11],al ;
- .endif ;
- mov bx,2 ;
- mov cx,14 ;
- mov dx,offset BCDSTR ;
- msdos 40h ;
- pop cx ;
- ret ;
- ENDN Display ;
- ;-------------------------------------------------------;
- ; Åëè·ë╗ --> SI
- ;-------------------------------------------------------;
- BEGIN Init ;
- mov BCD,1 ;
- mov BCD2,1 ;
- mov BCDSTR,CR ;
- mov BCDSTR[1],'(' ;
- mov BCDSTR[2],'0' ;
- mov BCDSTR[3],'0' ;
- mov BCDSTR[4],'0' ;
- mov BCDSTR[5],'0' ;
- mov BCDSTR[6],')' ;
- mov BCDSTR[7],'-' ;
- mov BCDSTR[8],'(' ;
- mov BCDSTR[9],'0' ;
- mov BCDSTR[10],'0' ;
- mov BCDSTR[11],'0' ;
- mov BCDSTR[12],'0' ;
- mov BCDSTR[13],')' ;
- ;-------------------------------------------------------;
- mov ax,DicSize ;
- mov bx,DicSize[2] ;
- .if <bx e 0 and <ax b MAXWORD>> ;
- mov CmpLen,ax ;
- .else ;
- mov CmpLen,MAXWORD ;
- .endif ;
- shl ax,1 ;
- rcl bx,1 ;
- shr ax,1 ;
- mov DicLen,ax ;
- mov DicPag,bx ;
- ;-------------------------------------------------------;
- .if <SrcSize[2] e 0 and <SrcSize b 8003h>> ;
- mov cx,SrcSize ;
- mov EndSrcFlg,TRUE ;
- .else ;
- mov cx,8003h ;
- mov EndSrcFlg,FALSE ;
- .endif ;
- mov SBufLen,cx ;
- mov bx,InHandle ;
- mov dx,offset RBuff ;
- msdos 3fh ;
- jc ErrOut ;
- cmp ax,cx ;
- jne ErrOut ;
- sub SrcSize,ax ;
- sbb SrcSize[2],0 ;
- call CrcCalc ;
- mov ax,SBufLen ;
- .if <ax b CmpLen> ;
- mov CmpLen,ax ;
- .endif ;
- ;-------------------------------------------------------;
- mov SftFlg,1 ;
- mov CodeBuf,0 ;
- mov CPoint,(offset CodeBuf)+1 ;
- mov WPoint,0 ;
- mov si,offset RBuff ;
- ret ;
- ENDN Init ;
- ;-----------------------------------------------------------------------------;
- ; EnCode256(in:word,out:word;dicsize,size:longint):boolean ;
- ;-----------------------------------------------------------------------------;
- BEGIN EnCode18 ;
- cld ;
- mov bx,sp ;
- mov PushSp,sp ;
- movdat InHandle ,ss:[bx+12] ;
- movdat OutHandle ,ss:[bx+10] ;
- movdat DicSize[2],ss:[bx+8] ;
- movdat DicSize ,ss:[bx+6] ;
- movdat SrcSize[2],ss:[bx+4] ;
- movdat SrcSize ,ss:[bx+2] ;
- call Init ;
- .while <CmpLen ne 0> ;
- call Search ;
- call Display ;
- call OutPut ;
- call ResetBuf ;
- .enddo ;
- .if <SftFlg ne 1> ;
- call CodeFlush ;
- .endif ;
- mov dx,offset WBuff ;
- mov bx,OutHandle ;
- mov cx,WPoint ;
- jcxz NrmOut ;
- msdos 40h ;
- jc ErrOut ;
- cmp ax,cx ;
- je NrmOut ;
- ErrOut: xor ax,ax ;
- jmp OutPro ;
- NrmOut: mov ax,1 ;
- OutPro: mov sp,PushSp ;
- ret 12 ;
- ENDN EnCode18 ;
- ;
- ;
- code ends ;
- end ;
- ;------------------------------------------------------------------------------